<template>
	<view class="service">
		<!-- <u-sticky> -->
			<view class="tops1">
				<view class="searchBox">
					<view class="search">
						<view class="inp">
							<u-search @change="changeInpFn"  :clearabled="true"  @clear="search" @search="search" bg-color="#fff" :show-action="false" height="60" search-icon=""
								placeholder-color="rgba(15, 20, 23, 0.3)" placeholder="请输入手机号或用户ID" v-model="keyword">
							</u-search>
						</view>
						<view class="btns" @click="search">
							搜索
						</view>
					</view>

				</view>
				<view class="selectOptions">
					<u-tabs
					bar-width="96"
					bar-height="4"
					inactive-color='rgba(15, 20, 23, 0.7)'
					active-color="rgba(15, 20, 23, 1)"
					font-size="28"
					 :bar-style="barStyle" :list="list" :is-scroll="false" :current="current" @change="change"></u-tabs>
				</view>
				<view class="borderGap">
					
				</view>
			</view>
		<!-- </u-sticky> -->
		<view  class="list" :style="{'padding-top': paddingTop}">
			<view @click="navTo('/subPack/service/list')" class="item">
				<image src="https://oss.6mate.cn/mini/Clipboard.png" mode=""></image>
				<view class="name">
					服务记录
				</view>
			</view>
			<view @click="scanner" class="item">
				<image src="https://oss.6mate.cn/mini/Scan-code1.png" mode=""></image>
				<view class="name">
					扫一扫
				</view>
			</view>
		</view>
		
	</view>
</template>

<script>
	
	export default {

		data() {
			return {
				keyword: '',
				paddingTop:""
			}
		},
		onLoad() {
		
			uni.createSelectorQuery().select('.tops1').boundingClientRect((rect) => {
				console.log(rect.height, 66666);
				this.paddingTop = rect.height + 12 + 'px'
			}).exec()
		},
		methods:{
			changeInpFn(e){
				
				if(e==''){
					this.memberGetFn(this.keyword)
				}
				
			},
			navTo(url){
				uni.navigateTo({
					url
				})
			},
			scanner(){
				let that = this;
				// 调起条码扫描
				uni.scanCode({
					scanType: ['qrCode'],
					success: function (res) {
						// console.log('条码类型：' + res.scanType);
						console.log('条码内容：' + res.result);
						that.memberGetFn(res.result)
					}
				});
			},
			memberGetFn(keyword){
				this.$u.api
					.memberGet({
						keyword,
						type:'SERVICE'
					})
					.then((res) => {
						
						if(res.code=='ok'){
							console.log(res?.data?.serviceRecordId, 77777);
							if(res?.data?.serviceRecordId){
								uni.navigateTo({
									url:"/subPack/service/detail?id="+res?.data?.serviceRecordId
								})
								
							}else{
								uni.navigateTo({
									url:"/subPack/service/add?type=SERVICE&keyword="+keyword
								})
							}
						}else{
							uni.showToast({
								icon:"none",
								title:res?.msg
							})
						}
						
						
						
					});
			},
			search(){
				if(!this.keyword){
					uni.showToast({
						title:"请输入手机号或ID号",
						icon:"none"
					})
					return;
				}
				this.memberGetFn(this.keyword)
				
			}
		}
	}
</script>


<style scoped lang="scss">
	.service {
		padding: 0 0 24rpx;
		.tops1 {
			background: #FFFFFF;
			padding: 24rpx 0 0;
			position: fixed;
			left: 0;
			top: 0;
			right: 0;
			z-index: 9;
		}
		.list {
			padding: 0 32rpx;
			display: flex;
			align-items: center;
			justify-content: space-between;
			.item{
				margin-top: 24rpx;
				display: flex;
				flex-direction: column;
				align-items: center;
				justify-content: center;
				width: 308rpx;
				height: 336rpx;
				background: #FFFFFF;
				box-shadow: 0rpx 20rpx 60rpx -1rpx rgba(132,132,132,0.1);
				border-radius: 48rpx 48rpx 48rpx 48rpx;
				image{
					width: 128rpx;
					height: 128rpx;
					display: block;
				}
				.name{
					font-family: Alibaba PuHuiTi, Alibaba PuHuiTi;
					font-weight: 400;
					font-size: 40rpx;
					color: #0F1417;
					line-height: 44rpx;
					margin-top: 26rpx;
				}
			}
			
		}

		.borderGap {
			// margin-bottom: 8rpx;
			// border-bottom: 2rpx solid #E7E7E7;
			margin-top: -4rpx;
			
		}

		.searchBox {
			display: flex;
			align-items: center;
			justify-content: space-between;
			margin: 0 32rpx 0;
		}

		.search {
			flex: 1;

			height: 64rpx;
			background: #FFFFFF;
			border-radius: 152rpx 152rpx 152rpx 152rpx;
			border: 2rpx solid #FA4A53;
			display: flex;
			align-items: center;
			justify-content: space-between;

			.inp {
				flex: 1;
			}

			.btns {
				display: flex;
				align-items: center;
				justify-content: center;
				font-family: Alibaba PuHuiTi, Alibaba PuHuiTi;
				font-weight: 400;
				font-size: 24rpx;
				color: #FFFFFF;
				line-height: 40rpx;
				margin: 4rpx;
				width: 128rpx;
				height: 56rpx;
				background: #FA4A53;
				border-radius: 152rpx 152rpx 152rpx 152rpx;
			}
		}

	}
</style>